
#ifndef SX_MASS_SPRING_MESH_STATE_H
#define SX_MASS_SPRING_MESH_STATE_H

#include <sxMassSpringMesh.h>
#include <sxStoredPhysicalRepresentation.h>

/* Sx library types. */
using Sx::Simulation::Objects::MassSpringMesh;
using Sx::Physics::StoredPhysicalRepresentation;

namespace Sx {
namespace Simulation {
namespace Recording {

/* 
 * Stores the state of the provided mesh reference. The provided mesh pointer
 * should reside within a valid MassSpringSimulation. The state of the mesh
 * will be stored upon the construction of a new MassSpringMeshState;
 */
class MassSpringMeshState {
public:
	MassSpringMeshState();
	virtual ~MassSpringMeshState();

	/* 
	 * Given a valid mass-spring mesh pointer, this function will copy the node
	 * data from the mesh into the meshStorage representation. This limited
	 * interface provides protection against the improper modification of the
	 * internal mesh pointer;
	 */
	bool save(const std::shared_ptr<MassSpringMesh>& mesh);
	bool load();

protected:
	/* 
	 * This works but I believe that it is very slow; but at least it wouldn't
	 * have a dangling pointer if the simulation was destroyed..
	 */
	std::shared_ptr<MassSpringMesh> mesh;

	/* 
	 * Stores the physical state of the mesh. The number of vertices should
	 * be equal to that defined by the provided mesh. (see load()/save() ).
	 */
	StoredPhysicalRepresentation meshStorage;

	/* 
	 * Copies the data from the internal mesh reference to the meshStorage
	 * representation (see construct(MassSpringMesh*) ).
	 */
	bool storeState();

	/*
	 * Copies the data stored in the meshStorage representation to the internal
	 * mesh reference.
	 */
	bool loadState();
};

}

}

}

#endif
